package com.codedancer.campus.client.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.client.service.ICarouselService;
import com.codedancer.campus.client.service.vo.carousel.CarouselVo;
import com.codedancer.campus.mapper.CarouselMapper;
import com.codedancer.campus.po.Carousel;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class CarouselServiceImpl implements ICarouselService {

    @Autowired
    private CarouselMapper carouselMapper;

    /**
     * 查询全部启用的轮播图
     *
     * @return
     */
    @Override
    public List<CarouselVo> listAllEnable() {
        List<Carousel> carousels = carouselMapper.listAllEnable();
        return carousels.stream()
            .map(carousel -> BeanUtil.copyProperties(carousel, CarouselVo.class)).collect(
                Collectors.toList());
    }
}
